package com.qf.service.impl;

import com.qf.dao.GoodsDao;
import com.qf.dao.impl.GoodsDaoImpl;
import com.qf.domain.Goods;
import com.qf.domain.GoodsType;
import com.qf.domain.PageBean;
import com.qf.service.GoodsService;
import com.qf.service.GoodsTypeService;

import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    private GoodsDao goodsDao=new GoodsDaoImpl();


    @Override
    public Goods selectById(Integer id) {
        Goods goods=goodsDao.findById(id);
        if(goods!=null){
            Integer typeid=goods.getTypeid();
            //goodsservlet?method=getGoodsListByTypeId&typeId=
            GoodsTypeService goodsTypeService=new GoodsTypeServiceImpl();
            GoodsType goodsType=goodsTypeService.selectByTypeid(typeid);
            goods.setGoodsType(goodsType);
        }
        return goods;
    }

    @Override
    public PageBean<Goods> SelectByPage(int page_num, int page_size, String where, List<Object> params) {
        long totalSize=goodsDao.getCount(where,params);
        List<Goods> data=goodsDao.selectByPage(page_num,page_size,where,params);
        PageBean<Goods> pageBean=new PageBean<Goods>(page_num,page_size,totalSize,data);
        return pageBean;
    }

    @Override
    public void insert(Goods goods) {
        goodsDao.add(goods);
    }

    @Override
    public List<Goods> selectGoods(String where, List<Object> params) {
        return goodsDao.findGoods(where,params);
    }

    @Override
    public void deleteById(String id) {
        goodsDao.removeById(id);
    }

    @Override
    public Goods select(String id) {
        return goodsDao.find(id);
    }

    @Override
    public void update(Goods goods) {
        goodsDao.modify(goods);
    }
}
